Skip to content

refactor: extract _console.py from __init__.py (PR-1/8)#2474

Open
darion-yaphet wants to merge 2 commits intogithub:mainfrom
darion-yaphet:refactor/split-init-pr1
Open

refactor: extract _console.py from __init__.py (PR-1/8)#2474
darion-yaphet wants to merge 2 commits intogithub:mainfrom
darion-yaphet:refactor/split-init-pr1

Conversation

@darion-yaphet
Copy link
Copy Markdown

Summary

Part 1 of 8 in the __init__.py module split refactor (design spec).

Extracts all Rich UI primitives from the 5880-line __init__.py into a focused _console.py base-layer module.

Moved symbols:

  • BANNER, TAGLINE — ASCII art constants
  • StepTracker — live progress tree renderer
  • get_key, select_with_arrows — interactive keyboard input
  • BannerGroup, show_banner — Typer banner integration
  • console — Rich Console singleton

Backward compatibility: All symbols remain importable from specify_cli via re-exports in __init__.py.

Dependency rule: _console.py has zero internal imports (base layer).

Test plan

  • New regression test tests/test_console_imports.py guards all 8 re-exported symbols
  • Full suite: 2788 passed, 34 skipped (baseline was 2786)
  • from specify_cli import console, StepTracker, ... works
  • specify --help renders banner correctly

@darion-yaphet darion-yaphet requested a review from mnriem as a code owner May 7, 2026 05:10
Move Rich UI primitives (BANNER, TAGLINE, StepTracker, get_key,
select_with_arrows, console, BannerGroup, show_banner) into a new
src/specify_cli/_console.py module. Re-export all symbols from
__init__.py to preserve the public API. Add regression guard tests.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is part 1/8 of the specify_cli/__init__.py split refactor, extracting Rich/Typer console UI primitives into a new base-layer module while keeping backward-compatible imports via re-exports from specify_cli.

Changes:

  • Added src/specify_cli/_console.py containing the Rich console singleton, banner rendering, keyboard input helpers, and StepTracker.
  • Updated src/specify_cli/__init__.py to import/re-export the extracted console symbols and removed their inlined implementations.
  • Added a regression test ensuring the extracted symbols remain importable from specify_cli.
Show a summary per file
File Description
src/specify_cli/_console.py New module housing the extracted Rich UI primitives and Typer banner group.
src/specify_cli/__init__.py Re-exports moved console symbols and removes the inlined implementations.
tests/test_console_imports.py Regression test to guard import compatibility for the re-exported console symbols.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment thread src/specify_cli/_console.py
Comment thread src/specify_cli/_console.py Outdated
Comment thread src/specify_cli/_console.py
…ptions

- Add module-level docstring documenting the console layer's purpose and
  the dependency-layering rule (no imports from other specify_cli modules)
- Tighten select_with_arrows() signature: options typed as dict[str, str]
  and default_key as str | None to align with repo typing style
- Add early ValueError guard when options is empty, preventing downstream
  ZeroDivisionError / IndexError inside the Live loop
@darion-yaphet darion-yaphet force-pushed the refactor/split-init-pr1 branch from 7da5416 to 0fd5a0c Compare May 7, 2026 16:35
@mnriem mnriem requested a review from Copilot May 7, 2026 17:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 5

from other ``specify_cli`` sub-modules; all dependencies must flow *into* this
layer, not out of it, to avoid circular imports.
"""
from __future__ import annotations

tree.add(line)
return tree

Comment on lines +154 to +155
if not options:
raise ValueError("select_with_arrows() requires at least one option.")
Comment on lines +43 to +44
def attach_refresh(self, cb):
self._refresh_cb = cb
Comment on lines +204 to +216
raise typer.Exit(1)

live.update(create_selection_panel(), refresh=True)

except KeyboardInterrupt:
console.print("\n[yellow]Selection cancelled[/yellow]")
raise typer.Exit(1)

run_selection_loop()

if selected_key is None:
console.print("\n[red]Selection failed.[/red]")
raise typer.Exit(1)
@mnriem
Copy link
Copy Markdown
Collaborator

mnriem commented May 7, 2026

Please address Copilot feedback

Copy link
Copy Markdown
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants